package org.snap.java.examples.analysis.text.edition1;

import java.util.*;    //means import the whole package!

public class CountWordsInText {
	
	public static void main (String[] args){
		System.out.println("This is my program :\n ha ha :)))");
		System.out.println("please enter a text:");
		
		Scanner input = new Scanner (System.in) ;
		
		String inputText = input.nextLine();
		
		String[] Words = inputText.split("[^a-zA-Z0-9]") ;  //space characters
		
		TreeMap<String, Integer> map =  new TreeMap<String, Integer>();
		
		for(int i = 0 ; i < Words.length;i++){
			String Key = Words[i].toLowerCase();
			if(Words[i].length()>1){    //yani more than 1 characters
				if (map.get(Key)==null){
					map.put(Key, 1);      //baraye bedoone tekrara
					
				}
				else {
					int value = map.get(Key).intValue();
					value++;
					map.put(Key, value);
				}
						
			}
			}
	
		
	

		
		System.out.print(map);
		}
}

